{extend name="index/index"}

 {block name="main"}
    <div class="admin-biaogelist">

        <div class="listbiaoti am-cf">
            <ul class="am-icon-flag on">商家审核</ul>
            <dl class="" style="float: right;"> 当前位置： 首页 > <a href="#">商家列表</a></dl>
        </div>


        <form class="am-form am-g">
            <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
                <thead>
                <tr class="am-success">
                    <th class="table-id">ID</th>
                    <th class="table-type">联系人 </th>
                    <th class="table-type">联系电话</th>
                    <th class="table-type">商家名/公司名</th>
                    <th class="table-type">身份证号/营业执照号</th>
                    <th class="table-type">身份照/营业执政照</th>
                    <th class="table-author">用户类型 </th>
                    <th class="table-author">审核状态 </th>
                    <th width="163px" class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="data" id="v"}
                <tr>
                    <td class="good_id" good_id="{$v.id}">{$v.id}</td>
                    <td>{$v.link_name}</td>
                    <td>{$v.link_phone}</td>
                    <td class="am-hide-sm-only">{$v.name_company}</td>
                    <td class="am-hide-sm-only">{$v.id_reg}7</td>
                    <td class="am-hide-sm-only"><img src="/uploads/business/{:str_replace('\','/',$v.ros_charter)}" width="100px" height="50px"></td>
                    <td class="am-hide-sm-only">{if condition="$v.usertype eq 0 "}个人
                                                {else /} 企业
                                                {/if}</td>
                    <td class="am-hide-sm-only updateaudit">{if condition="$v.audit eq 0 "}待审核
                                                {elseif condition="$v.audit eq 1 " /} 审核通过
                                                 {else /}未通过审核
                                                {/if}</td>
                    <td><div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <button data-id="{$v.id}" static_id="{$v.audit}" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary am-round" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="clicks(this)">修改状态</button>
                        </div>
                    </div>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </form>
        <ul class="am-pagination am-fr">
            {$data->render()}
        </ul>
    </div>


<!-- 修改状态 小模态框 -->

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content" >
            <div style="margin-left:10%;">
                <h4>修改状态</h4>
                <hr/>
           <form class="myform">
               <input type="radio" name="audit" value="0"> 待审核
               <input type="radio" name="audit" value="1"> 审核通过
               <input type="radio" name="audit" value="2"> 审核不通过
               <br/>
               <button type="button" class="btn btn-default goodupdate" data-dismiss="modal">确认修改</button>
           </form>
          </div>
        </div>
    </div>
</div>
<script>
       function clicks(t) {
           var id = $(t).attr('data-id');
           var static_id = $(t).attr('static_id');
           var button = $('.myform button[type="button"]');
           var radio = $('.myform input[type="radio"]');

           for(var i=0; i<radio.length; i++) {
               if ($(radio[i]).val() == static_id) {
                   $(radio[i]).attr("checked",true);
                   button.attr('good_id',id);
               }
           }

       }
    $('.goodupdate').click(function(){
            var id = $(this).attr('good_id');
            var audit = $("input[type='radio']:checked").val();
            $.ajax({
                url : '/admin/goodajax',
                type : 'post',
                dateType : 'json',
                data : {'id':id,'audit':audit},
                success : function(data){
                    if(data){
                        $(".good_id").each(function () {

                            if ($(this).attr('good_id') == id) {

                                switch(audit) {
                                    case '0':
                                        $($(this).parents("tr").children('.updateaudit')[0]).html('待审核');
                                        break;
                                    case '1':
                                        $($(this).parents("tr").children('.updateaudit')[0]).html('审核通过');
                                        break;
                                    case '2':
                                        $($(this).parents("tr").children('.updateaudit')[0]).html('审核不通过');
                                        break;

                                }
                            }
                        });
                    }else{
                        alert('审核失败请重试');
                    }
                },
                error : function(){
                    alert('ajax执行失败');
                }

            })

    })
</script>
{/block}
